package com.mine.distinctionteam.ui.home;


import android.os.Handler;
import android.os.Looper;
import com.mine.distinctionteam.base.IView;
import com.mine.distinctionteam.bean.home.HomeBean;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 *
 */
public class HomePresenter implements HomeContract.Presenter {
    private HomeContract.View view;
    private HomeContract.Model model;
    public HomePresenter(HomeContract.View view) {
        this.view = view;
        model = new HomeModel();
    }
    @Override
    public void getHome() {
        model.getHome(new Callback<HomeBean>() {
            @Override
            public void onResponse(Call<HomeBean> call, Response<HomeBean> response) {
                final HomeBean homeBean = response.body();
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getHomeSuccess(homeBean);
                    }
                });
            }
            @Override
            public void onFailure(Call<HomeBean> call, Throwable t) {
                view.getHomeFail(" 网络加载失败了 ");
            }
        });

    }
    @Override
    public void detachView() {

    }
    @Override
    public void attachView(IView view) {

    }
}
